#include "actioncondition.h"


ActionCondition::ActionCondition(const QJsonObject &base, const QString &key,
                                 const QJsonValue &cond1, const QJsonValue &cond2)
{
    classname = __FUNCTION__;
    actParam = QJsonObject();
    actParam.insert("base",QJsonValue(base));
    actParam.insert("key",key);
    actParam.insert("cond1",cond1);
    actParam.insert("cond2",cond2);
}

int ActionCondition::execute()
{
    QJsonObject base = actParam.value("base").toObject();
    QString key = actParam.value("key").toString();
    QJsonValue cond1 = actParam.value("cond1");
    QJsonValue cond2 = actParam.value("cond2");

    QJsonValue rst = base.value(key);
    qInfo()<<classname<<"base value:"<<rst<<"cond1:"<<cond1<<"cond2:"<<cond2;
    if(rst == cond1) return 1;
    if(rst == cond2) return 2;
}
